<template>
	<view class="container">
		<view class="view_line"></view>
		<view class="position">
			<view class="search_key">
				<view v-for='(item,index) in hot' :key="index" class="search_key_scroll" 
				@click ="toSearch(item.name)">
						{{item.name}}
				</view>
			</view>
			<view class="list_sort">
				<view class="sort_list">
					<view class="picker" @click="slectCity">
						<text>{{city}}</text>
						<image src="/static/img/buttom.png"></image>
					</view>
				</view>
				
				<view class="sort_list">
					<picker @change="bindPickerChange" :value="jobIndex" :range="job" 
					range-key="name" data-index="jobIndex">
						<view class="picker">
						{{jobText}}
						<image src="/static/img/buttom.png">
						</view>
					</picker>
				</view>
				
				<view class="sort_list">
					<picker @change="bindPickerChange" :value="workIndex" :range="pickWorkArr"
					data-index="workIndex">
						<view class="uni-input">
						{{pickWorkArr[workIndex]}}
						<image src="/static/img/buttom.png">
						</view>
					</picker>
				</view>
			</view>
		</view>
		<view class="news">
			<!-- <view class="view_line"></view> -->
			<view class="newslist" v-for='(item,index) in member' :key="index">
				<view @click="toDetail(item.uid)" class="title">
					<view class="detail">
						<view class="pic">
							<view class="jobtitle">{{item.post}}</view>
							<image v-if="item.realPic" :src="imgUrl+item.realPic"></image>
							<image v-else :src="item.avatar"></image>
						</view>
	
						<view class="info">
							<view>{{item.realname}}</view>
							<view>星级:<image class="star" :src="getImgUrl(item.star)"></image></view>
						</view>
						<view class="info">联系电话:{{item.phone}}</view>
						<view class="info"> {{item.sex}} / {{item.age}}岁 / {{item.workTime}} / {{item.education}}</view>
						<view class="info" v-if="item.advantage">特长:{{item.advantage}}</view>
						<view class="info" v-else>特长:暂无填写</view>
					</view>
				</view>
			</view>
		</view>
		
		<view @click="jumpVip" v-if="role == 3" class="frame">VIP</view>
	</view>
</template>
<script>
import request from '@/util/request.js'	
export default {
	data() {
		return {
			iStatusBarHeight:0,
			role:0,
			imgUrl:this.url,
			city:'全部',
			jobText:'',
			jobIndex:0,
			workIndex:0,
			job:[],
			hot:[],
			totalPage:0,
			page:1,
			star:'',
			jobCate:[
				{
					'id':0,
					'name':'全部',
					'addtime':'2020-10-20',
				}
			],
			pickJobArr:[
				{
					'id':0,
					'name':'工作岗位',
					'addtime':'2020-10-20',
				}
			],
			pickWorkArr: ['工作经验','1年','2年','3年','4年','5年以上'],
			member:[]
		}
	},
	onLoad:function(e){
		this.role = uni.getStorageSync('role')
		// uni.showLoading({
		//     title: '加载中'  
		// });
		if(e.star){
			this.star = e.star
		}
		this.getHot();
		this.getJob();
		// this.page = 1;
		// this.pageShow = true,
		// this.getMember()
	},
	onShow:function(){
		uni.showLoading({
		    title: '加载中'  
		});
		this.member = []
		this.page = 1;
		this.pageShow = true,
		this.getMember()
	},
	methods: {
		getHot:function(){
			var that = this;
			var hot = this.jobCate
			request({
				url: 'job/hot',
				method: 'get',
				success: (res) => {
					that.hot = hot.concat(res.data.data)
				}
			})
		},
		getJob:function(){
			var that = this;
			var pickJobArr = this.pickJobArr
			request({
				url: 'job/list',
				method: 'get',
				success: (res) => {
					that.job = pickJobArr.concat(res.data.data)
					that.jobText = that.job[that.jobIndex]['name']
				}
			})
		},
		getMember:function(){
			var that = this;
			if(this.city == '全部'){
			    var city = '';
			}else{
				var city = this.city;
			}
			if(this.workIndex == 0){
			    var workText = '';
			}else{
				var workText = this.pickWorkArr[this.workIndex];
			}
			if(this.jobText == '工作岗位' || this.jobText == '全部'){
			    var jobText = '';
			}else{
				var jobText = this.jobText;
			}
			var data = {
				'page':this.page,
				'cateName':jobText,
				'workType':workText,
				'star':this.star,
				'city':city
			}
			request({
				url: 'member/list',
				method: 'get',
				data:data,
				success: (res) => {
					uni.hideLoading();
					if(that.page == 1){
						that.totalPage = res.data.data.last_page
						that.member = res.data.data.data
					}else{
						var member = that.member
						that.member = member.concat(res.data.data.data)
					}
				}
			})
		},
		bindPickerChange:function(e){
			var key = e.detail.value
			var index = e.currentTarget.dataset.index
			if(index == 'jobIndex'){
				this.jobText = this.job[key]['name']
			}
			this[index] = key
			this.page = 1
			uni.showLoading()
			this.getMember();
		},
		toSearch:function(name){
			this.jobText = name
			this.page = 1
			uni.showLoading()
			this.getMember();
		},
		onReachBottom: function(){
			if(this.page < this.totalPage){
				 //当前不是最后一页可加载
				 this.page = this.page + 1
				 uni.showLoading()
				 this.getMember();
			}
		},
		jump:function(id){
			uni.navigateTo({
				url:'/pages/lease/info?id='+id
			});
		},
		jumpVip:function(){
			uni.navigateTo({
				url:'/pages/vip/index'
			});
		},
		getImgUrl:function(url){
			return require("@/static/img/star_"+url+".png");
		},
		slectCity:function(){
			uni.navigateTo({
				url:'/pages/city/index'
			});
		},
		toDetail:function(uid){
			uni.navigateTo({
				url:'/pages/job/info?uid='+uid
			});
			return;
			if(uni.getStorageSync('role') == 99){
				uni.navigateTo({
					url:'/pages/job/info?uid='+uid
				});
				return;
			}
			var role = uni.getStorageSync('role')
			if(role == 3){
				//查询是否 审核通过
				var data = {'uid':uni.getStorageSync('uid')}
				request({
					url: 'member/status',
					method: 'get',
					data:data,
					success: (res) => {
						if(res.data.data.status == 3){
							uni.navigateTo({
								url:'/pages/job/info?uid='+uid
							});
						}else{
							uni.showToast({
								title: '暂未审核活审核未通过!!',
								icon: "none", 
								position:'bottom',
							});
							return;
						}
					}
				})
			}else{
				uni.showToast({
					title: '暂未权限!!',
					icon: "none", 
					position:'bottom',
				});
				return;
			}
		}
	}
}
</script>
<style scoped>
	@import url("./css/index.css");
</style>